#ifndef _TCPSERVERBASE_H
#define _TCPSERVERBASE_H

#include "base.h"

class CTcpserverbase
{
public:
	CTcpserverbase(LPST_ENV_T pEnv, int nPort);
	virtual ~CTcpserverbase();

private:
	static void cb_OnAccept(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *address, int socklen,
		void *ctx){((CTcpserverbase*)ctx)->OnAccept(fd, address, socklen);};
	virtual void OnAccept(evutil_socket_t fd, struct sockaddr *address, int socklen){};
	static void cb_OnAcceptError(struct evconnlistener *listener, void *ctx){((CTcpserverbase*)ctx)->OnAcceptError(listener);};
	void OnAcceptError(struct evconnlistener *listener);
	
	static void cbTimerTask(int fd, short events, void* ctx){((CTcpserverbase*)ctx)->OnTimer(fd, events);};
	void OnTimer(int fd, short events);
	void CreateServer(int nPort);
protected:
	LPST_ENV_T m_pEnv;
	struct evconnlistener *m_pListener;
	void SendOutOnMulti(char* pDevid, char* pCmdSend);

	timer_param_t m_nTimer;
};

#endif
